package de.breitbeil.jbooking.domain;

import java.util.Date;
import java.util.Set;

public class Booking {

	/** 1000ms * 60s * 60min * 24h */
	private static int hourInMillis = 1000 * 60 * 60;
	private static int dayInMillis = hourInMillis * 24;
	
    private Long id;
    private Date from;
    private Date to;
    private Date bookingDate;
    private Person person;
    private String comment;
    private TBookingType bookingType;
    private Integer numberAdults;
	private Integer numberChildren;
    private Integer numberDogs;
    private Double prepayment;
    private Double price;
    private Double vtax;
    private String vtax_no;
    private Set<Event> events;
    
    public Long getId() {
        return id;
    }
    public void setId(Long id) {
        this.id = id;
    }
    public Date getFrom() {
        return from;
    }
    public void setFrom(Date from) {
        this.from = from;
    }
    public Date getTo() {
        return to;
    }
    public void setTo(Date to) {
        this.to = to;
    }
    public Date getBookingDate() {
        return bookingDate;
    }
    public void setBookingDate(Date bookingDate) {
        this.bookingDate = bookingDate;
    }
    public Person getPerson() {
        return person;
    }
    public void setPerson(Person person) {
        this.person = person;
    }
    public String getComment() {
        return comment;
    }
    public void setComment(String comment) {
        this.comment = comment;
    }
    public TBookingType getBookingType() {
        return bookingType;
    }
    public void setBookingType(TBookingType bookingType) {
        this.bookingType = bookingType;
    }
    public Integer getNumberAdults() {
		return numberAdults;
	}
	public void setNumberAdults(Integer numberAdults) {
		this.numberAdults = numberAdults;
	}
	public Integer getNumberChildren() {
		return numberChildren;
	}
	public void setNumberChildren(Integer numberChildren) {
		this.numberChildren = numberChildren;
	}
	public Integer getNumberDogs() {
		return numberDogs;
	}
	public void setNumberDogs(Integer numberDogs) {
		this.numberDogs = numberDogs;
	}
	public Double getPrepayment() {
		return prepayment;
	}
	public void setPrepayment(Double prepayment) {
		this.prepayment = prepayment;
	}
	public Double getPrice() {
		return price;
	}
	public void setPrice(Double price) {
		this.price = price;
	}
    public void setEvents(Set<Event> events) {
        this.events = events;
    }
    public Set<Event> getEvents() {
        return events;
    }
    public void setNumDays(int numDays) {
    	
    }
    public int getNumDays() {
    	return getNumDays(from, to);
    }
	public void setVtax(Double vtax) {
		this.vtax = vtax;
	}
	public Double getVtax() {
		return vtax;
	}

	public void setVtax_no(String vtax_no) {
		this.vtax_no = vtax_no;
	}
	public String getVtax_no() {
		return vtax_no;
	}

    static public int getNumDays(Date from, Date to) {
    	int days = 0;
		if(from != null && to != null) {
			long diffInMillis = to.getTime() - from.getTime();
			diffInMillis = diffInMillis + hourInMillis; // For switch to summer time
			days = (int) (diffInMillis / dayInMillis);
		}
		return days;
    }
    
    @Override
    public int hashCode() {
        final Integer prime = 31;
        int result = 1;
        result = prime * result + ((id == null) ? 0 : id.hashCode());
        return result;
    }
    @Override
    public boolean equals(Object obj) {
        if (this == obj)
            return true;
        if (obj == null)
            return false;
        if (getClass() != obj.getClass())
            return false;
        Booking other = (Booking) obj;
        if (id == null) {
            if (other.id != null)
                return false;
        } else if (!id.equals(other.id))
            return false;
        return true;
    }
    
}
